package com.chinastock.log;

import com.chinastock.Constant;
import org.apache.logging.log4j.ThreadContext;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;

import java.util.UUID;

/**
 * @author zhangfan.it
 * @date 2021/1/21
 */
@Component
@Order(Filters.CONTEXTS)
public class ContextFilter implements WebFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange serverWebExchange, WebFilterChain webFilterChain) {
        //TODO:补充skywalking的traceid
        String uuid = UUID.randomUUID().toString().replaceAll("-","");
        ThreadContext.put(Constant.TRACE_ID, uuid);
        ThreadContext.put(Constant.SPAN_ID, uuid);
        return webFilterChain.filter(serverWebExchange);
    }
}
